package com.example.weight.greenSeasons.flocculation;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.weight.R;
import com.example.weight.config.Config;
import com.example.weight.greenSeasons.flocculation.xuningribaoyang;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import net.cachapa.expandablelayout.ExpandableLayout;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

public class xuningribaoyang extends AppCompatActivity {
    //设备名称
    private TextView name1,name2,name3,name4,name5,name6;

    private ExpandableLayout expand_1;
    private ExpandableLayout expand_2;
    private ExpandableLayout expand_3;
    private Button textView1;
    private Button textView2;
    private Button textView3;
    private TextView dateEdit;
    private TitleBar titleBar;


    private String name, role, factory;
    private Map<String, String> fromIdMap;

    private RadioGroup rg1, rg2, rg3, rg4, rg5, rg6;
    private RadioButton rb1Normal, rb1Abnormal, rb2Normal, rb2Abnormal, rb3Normal, rb3Abnormal
            , rb4Normal, rb4Abnormal, rb5Normal, rb5Abnormal, rb6Normal, rb6Abnormal;

    private RequestQueue queue;


    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xuningribaoyang);

        Intent previousIntent = getIntent();
        name = previousIntent.getStringExtra("name");
        role = previousIntent.getStringExtra("role");
        factory = previousIntent.getStringExtra("factory");

        expand_1=findViewById(R.id.expandable_1);
        expand_2=findViewById(R.id.expandable_2);
        expand_3=findViewById(R.id.expandable_3);
        textView1=findViewById(R.id.button_1);
        textView2=findViewById(R.id.button_2);
        textView3=findViewById(R.id.button_3);
        dateEdit=findViewById(R.id.compost_editDate);

        //设备名称
        name1=findViewById(R.id.xuningDaily_weiliaobeng1);
        name2=findViewById(R.id.xuningDaily_weiliaobeng2);
        name3=findViewById(R.id.xuningDaily_tuoshui1);
        name4=findViewById(R.id.xuningDaily_tuoshui2);
        name5=findViewById(R.id.xuningDaily_tuoshui3);
        name6=findViewById(R.id.xuningDaily_chuchou);

        Calendar calendar=Calendar.getInstance();
        Integer year = calendar.get(Calendar.YEAR);
        Integer month = calendar.get(Calendar.MONTH)+1; //第一个月从0开始，所以得到月份＋1
        Integer day = calendar.get(calendar.DAY_OF_MONTH);
        Integer hour24 = calendar.get(calendar.HOUR_OF_DAY);
        Integer minute = calendar.get(calendar.MINUTE);
        dateEdit.setText(year+"-"+month+"-"+day);

        titleBar=findViewById(R.id.titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {

            @Override
            public void onLeftClick(View v) {
                if (rg1.getCheckedRadioButtonId() == -1) {
                    allDone(name1.getText().toString());
                }else if (rg2.getCheckedRadioButtonId() == -1) {
                    allDone(name2.getText().toString());
                }else if (rg3.getCheckedRadioButtonId() == -1) {
                    allDone(name3.getText().toString());
                }else if (rg4.getCheckedRadioButtonId() == -1) {
                    allDone(name4.getText().toString());
                }else if (rg5.getCheckedRadioButtonId() == -1) {
                    allDone(name5.getText().toString());
                }else if (rg6.getCheckedRadioButtonId() == -1) {
                    allDone(name6.getText().toString());
                }else {
                    xuningribaoyang.this.finish();
                }
            }
            @Override
            public void onTitleClick(View v) {}
            @Override
            public void onRightClick(View v) {}
        });

        // Radio Group
        rg1 = findViewById(R.id.rg_feed_pump_1);
        rg2 = findViewById(R.id.rg_feed_pump_2);
        rg3 = findViewById(R.id.rg_de_water_1);
        rg4 = findViewById(R.id.rg_de_water_2);
        rg5 = findViewById(R.id.rg_de_water_3);
        rg6 = findViewById(R.id.rg_deodorant);

        //Radio Button Normal
        rb1Normal = findViewById(R.id.rb_feed_pump_1_normal);
        rb2Normal = findViewById(R.id.rb_feed_pump_2_normal);
        rb3Normal = findViewById(R.id.rb_de_water_1_normal);
        rb4Normal = findViewById(R.id.rb_de_water_2_normal);
        rb5Normal = findViewById(R.id.rb_de_water_3_normal);
        rb6Normal = findViewById(R.id.rb_deodorant_normal);

        //Radio Button Abnormal
        rb1Abnormal = findViewById(R.id.rb_feed_pump_1_abnormal);
        rb2Abnormal = findViewById(R.id.rb_feed_pump_2_abnormal);
        rb3Abnormal = findViewById(R.id.rb_de_water_1_abnormal);
        rb4Abnormal = findViewById(R.id.rb_de_water_2_abnormal);
        rb5Abnormal = findViewById(R.id.rb_de_water_3_abnormal);
        rb6Abnormal = findViewById(R.id.rb_deodorant_abnormal);

        fromIdMap = new HashMap<>();

        queue = Volley.newRequestQueue(this);

       //equip_1
        rb1Normal.setOnClickListener(v -> {
            if (rb1Normal.isChecked()) {
                saveNormal(name1.getText().toString(), rb1Abnormal, rb1Normal,rg1);
            }
        });
        rb1Abnormal.setOnClickListener(v -> {
            if (rb1Abnormal.isChecked()) {
                saveAbnormal(name1.getText().toString(), rb1Abnormal, rb1Normal,rg1);
            }
        });
        //equip_2
        rb2Normal.setOnClickListener(v -> {
            if (rb2Normal.isChecked()) {
                saveNormal(name2.getText().toString(), rb2Abnormal, rb2Normal,rg2);
            }
        });
        rb2Abnormal.setOnClickListener(v -> {
            if (rb2Abnormal.isChecked()) {
                saveAbnormal(name2.getText().toString(), rb2Abnormal, rb2Normal,rg2);
            }
        });
        //equip_3
        rb3Normal.setOnClickListener(v -> {
            if (rb3Normal.isChecked()) {
                saveNormal(name3.getText().toString(), rb3Abnormal, rb3Normal,rg3);
            }
        });
        rb3Abnormal.setOnClickListener(v -> {
            if (rb3Abnormal.isChecked()) {
                saveAbnormal(name3.getText().toString(), rb3Abnormal, rb3Normal,rg3);
            }
        });
        //equip_4
        rb4Normal.setOnClickListener(v -> {
            if (rb4Normal.isChecked()) {
                saveNormal(name4.getText().toString(), rb4Abnormal, rb4Normal,rg4);
            }
        });
        rb4Abnormal.setOnClickListener(v -> {
            if (rb4Abnormal.isChecked()) {
                saveAbnormal(name4.getText().toString(), rb4Abnormal, rb4Normal,rg4);
            }
        });
        //equip_5
        rb5Normal.setOnClickListener(v -> {
            if (rb5Normal.isChecked()) {
                saveNormal(name5.getText().toString(), rb5Abnormal, rb5Normal,rg5);
            }
        });
        rb5Abnormal.setOnClickListener(v -> {
            if (rb5Abnormal.isChecked()) {
                saveAbnormal(name5.getText().toString(), rb5Abnormal, rb5Normal,rg5);
            }
        });
        //equip_6
        rb6Normal.setOnClickListener(v -> {
            if (rb6Normal.isChecked()) {
                saveNormal(name6.getText().toString(), rb6Abnormal, rb6Normal,rg6);
            }
        });
        rb6Abnormal.setOnClickListener(v -> {
            if (rb6Abnormal.isChecked()) {
                saveAbnormal(name6.getText().toString(), rb6Abnormal, rb6Normal,rg6);
            }
        });

        //获取当天最新一条数据
        RequestQueue queue = Volley.newRequestQueue(this);
        String url = Config.url + "/sjq/flocculationProduceMaintenanceDay/getDailyRecords" + "?factory=" + factory;
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            Log.d("jy", response);
                            JSONArray data;
                            if(jsonObject.get("data")!=null && !jsonObject.get("data").toString().equals("null")) {
                                data = jsonObject.getJSONArray("data");
                                if(data.length()>0){
                                    for(int i=0;i<data.length();i++){
                                        // 遍历 jsonarray 数组，把每一个对象转成 json 对象
                                        JSONObject record = data.getJSONObject(i);
                                        // 得到 每个对象中的属性值
                                        if (record.get("equipmentName").equals(name1.getText().toString())){
                                            if(record.get("isNormal").equals("正常")){
                                                rb1Normal.setChecked(true);
                                            }else {
                                                rb1Abnormal.setChecked(true);
                                            }
                                            if(record.get("operator")!=null){
                                                rb1Normal.setClickable(false);
                                                rb1Abnormal.setClickable(false);
                                            }
                                        }else if (record.get("equipmentName").equals(name2.getText().toString())){
                                            if(record.get("isNormal").equals("正常")){
                                                rb2Normal.setChecked(true);
                                            }else {
                                                rb2Abnormal.setChecked(true);
                                            }
                                            if(record.get("operator")!=null){
                                                rb2Normal.setClickable(false);
                                                rb2Abnormal.setClickable(false);
                                            }
                                        }else if (record.get("equipmentName").equals(name3.getText().toString())){
                                            if(record.get("isNormal").equals("正常")){
                                                rb3Normal.setChecked(true);
                                            }else {
                                                rb3Abnormal.setChecked(true);
                                            }
                                            if(record.get("operator")!=null){
                                                rb3Normal.setClickable(false);
                                                rb3Abnormal.setClickable(false);
                                            }
                                        }else if (record.get("equipmentName").equals(name4.getText().toString())){
                                            if(record.get("isNormal").equals("正常")){
                                                rb4Normal.setChecked(true);
                                            }else {
                                                rb4Abnormal.setChecked(true);
                                            }
                                            if(record.get("operator")!=null){
                                                rb4Normal.setClickable(false);
                                                rb4Abnormal.setClickable(false);
                                            }
                                        }else if (record.get("equipmentName").equals(name5.getText().toString())){
                                            if(record.get("isNormal").equals("正常")){
                                                rb5Normal.setChecked(true);
                                            }else {
                                                rb5Abnormal.setChecked(true);
                                            }
                                            if(record.get("operator")!=null){
                                                rb5Normal.setClickable(false);
                                                rb5Abnormal.setClickable(false);
                                            }
                                        }else if (record.get("equipmentName").equals(name6.getText().toString())){
                                            if(record.get("isNormal").equals("正常")){
                                                rb6Normal.setChecked(true);
                                            }else {
                                                rb6Abnormal.setChecked(true);
                                            }
                                            if(record.get("operator")!=null){
                                                rb6Normal.setClickable(false);
                                                rb6Abnormal.setClickable(false);
                                            }
                                        }
                                    }
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(xuningribaoyang.this,
                        "获取信息失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(stringRequest);
    }
//    private void operatorAddForm(CheckBox checkBox, String comment) {
//        String[] temp = checkBox.getText().toString().split("[ \n]");
//        String fName = temp[0];
//        String maintainContent = temp[1];
//        new android.app.AlertDialog.Builder(this)
//                .setTitle("确定提交吗？")
//                .setCancelable(false)
//                .setNegativeButton("取消", ((dialog, which) -> checkBox.setChecked(false)))
//                .setPositiveButton("确定", (dialog, which) -> {
//                    checkBox.setEnabled(false);
//                    String url = Config.url + "/sjq/flocculationProduceMaintenanceDay/add_recorder";
//                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
//                            new Response.Listener<String>() {
//                                @Override
//                                public void onResponse(String response) {
//                                    try {
//                                        JSONObject jsonObject = new JSONObject(response);
//                                        String code = jsonObject.getString("code");
//
//                                        if (code.startsWith("2"))
//                                            Toast.makeText(xuningribaoyang.this,
//                                                    "保存成功", Toast.LENGTH_SHORT).show();
//                                        else
//                                            Toast.makeText(xuningribaoyang.this,
//                                                    "保存失败", Toast.LENGTH_SHORT).show();
//                                    } catch (JSONException e) {
//                                        e.printStackTrace();
//                                    }
//                                }
//                            }, new Response.ErrorListener() {
//                        @Override
//                        public void onErrorResponse(VolleyError error) {
//                            Toast.makeText(xuningribaoyang.this,
//                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
//                        }
//                    }) {
//                        @Override
//                        protected Map<String, String> getParams() {
//                            Map<String, String> map=new HashMap<>();
//                            map.put("equipment_name", fName);
//                            map.put("operator", name);
//                            map.put("maintenance_content", maintainContent);
//                            map.put("remarks", comment);
//                            return map;
//                        }
//                    };
//                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
//                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
//                    queue.add(stringRequest);
//                }).show();
//    }
//
//    private void setCheckStatus(CheckBox operatorCB, CheckBox examinerCB) throws UnsupportedEncodingException {
//        String operatorCBText = operatorCB.getText().toString();
//        String[] temp = operatorCBText.split("[ \n]");
//        String fName = URLEncoder.encode(temp[0], "utf-8");
//        String maintainContent = URLEncoder.encode(temp[1], "utf-8");
//
//        String url = Config.url + "/sjq/flocculationProduceMaintenanceDay/getlatest"+"?equipment_name="+fName+"&maintenance_content="+maintainContent;
//        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
//                new Response.Listener<String>() {
//                    @Override
//                    public void onResponse(String response) {
//                        Log.d("res",response);
//                        try {
//                            JSONObject jsonObject = new JSONObject(response);
//                            if (!jsonObject.isNull("data")) {
//                                JSONObject data = jsonObject.getJSONObject("data");
//                                operatorCB.setChecked(true);
//                                operatorCB.setEnabled(false);
//                                operatorCB.setTextColor(Color.GREEN);
////                                setRemarks(operatorCB, data.getString("remarks"));
//
//                                String examiner = data.getString("examiner");
//                                if (!examiner.equals("") && !examiner.equals("null")) {
//                                    // 检查人已检查某项，该项不可再检查
//                                    examinerCB.setChecked(true);
//                                    examinerCB.setEnabled(false);
//                                    examinerCB.setTextColor(Color.GREEN);
//                                } else {
//                                    // 若存在检查人未检查项，将其添加到formIdList中
//                                    fromIdMap.put(operatorCBText, data.getString("id"));
//                                }
//                            } else {
//                                if (role.equals("检查人")) {
//                                    // 如果操作人未保养，检查人不可检查
//                                    operatorCB.setEnabled(false);
//                                    examinerCB.setEnabled(false);
//                                }
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                Toast.makeText(xuningribaoyang.this,
//                        "失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
//            }
//        });
//        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
//                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
//        queue.add(stringRequest);
//    }
//
//    private void examinerAddForm(String formId, String comment, CheckBox checkBox) {
//        new android.app.AlertDialog.Builder(this)
//                .setTitle("确定检查吗？")
//                .setCancelable(false)
//                .setNegativeButton("取消", ((dialog, which) -> checkBox.setChecked(false)))
//                .setPositiveButton("确定", (dialog, which) -> {
//                    checkBox.setEnabled(false);
//                    String url = Config.url + "/sjq/flocculationProduceMaintenanceDay/add_examiner";
//                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
//                            new Response.Listener<String>() {
//                                @Override
//                                public void onResponse(String response) {
//                                    try {
//                                        JSONObject jsonObject = new JSONObject(response);
//                                        String code = jsonObject.getString("code");
//
//                                        if (code.startsWith("2"))
//                                            Toast.makeText(xuningribaoyang.this,
//                                                    "保存成功", Toast.LENGTH_SHORT).show();
//                                        else
//                                            Toast.makeText(xuningribaoyang.this,
//                                                    "保存失败", Toast.LENGTH_SHORT).show();
//                                    } catch (JSONException e) {
//                                        e.printStackTrace();
//                                    }
//                                }
//                            }, new Response.ErrorListener() {
//                        @Override
//                        public void onErrorResponse(VolleyError error) {
//                            Toast.makeText(xuningribaoyang.this,
//                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
//                        }
//                    }) {
//                        @Override
//                        protected Map<String, String> getParams() {
//                            Map<String, String> map=new HashMap<>();
//                            map.put("Id", formId);
//                            map.put("examiner", name);
//                            map.put("remarks", comment);
//                            return map;
//                        }
//                    };
//                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
//                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
//                    queue.add(stringRequest);
//                }).show();
//    }

//    private void setRemarks(CheckBox checkBox, String remarks) {
//        switch (checkBox.getText().toString()) {
//            case "喂料泵1 擦拭卫生":
//                weiliaobeng1Remark.setText(remarks);
//                break;
//            case "喂料泵2 擦拭卫生":
//                weiliaobeng2Remark.setText(remarks);
//                break;
//            case "1#絮凝脱水系统 擦拭清理冲洗内部":
//                tuoshui1Remark.setText(remarks);
//                break;
//            case "2#絮凝脱水系统 擦拭清理冲洗内部":
//                tuoshui2Remark.setText(remarks);
//                break;
//            case "3#絮凝脱水系统 擦拭清理冲洗内部":
//                tuoshui3Remark.setText(remarks);
//                break;
//            case "除臭系统 擦拭检查噪声":
//                chuchouRemark.setText(remarks);
//                break;
//            default:
//        }
//    }

    public void show1(View view) {
        if (expand_1.isExpanded()){
            textView1.setText("+ 擦拭卫生");
        }else{
            textView1.setText("- 擦拭卫生");
        }

        expand_1.toggle();
    }
    public void show2(View view) {
        if (expand_2.isExpanded()){
            textView2.setText("+ 擦拭清理冲洗内部");
        }else{
            textView2.setText("- 擦拭清理冲洗内部");
        }

        expand_2.toggle();
    }
    public void show3(View view) {
        if (expand_3.isExpanded()){
            textView3.setText("+ 擦拭表面卫生清理冲洗内部");
        }else{
            textView3.setText("- 擦拭表面卫生清理冲洗内部");
        }

        expand_3.toggle();
    }

//    public void save(View view) {
//        new AlertDialog.Builder(this)
//                .setTitle("确定保存吗？")
//                .setCancelable(false)
//                .setNegativeButton("取消", ((dialog, which) ->
//                        Toast.makeText(this, "取消保存", Toast.LENGTH_SHORT).show()))
//                .setPositiveButton("确定", (dialog, which) ->
//                        Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show())
//                .show();
//    }

    public void saveNormal(String equipment_name, RadioButton normal_rb, RadioButton abnormal_rb,RadioGroup rb) {
        new AlertDialog.Builder(this)
                .setTitle("确定 “"+ equipment_name +"” 正常？")
                .setCancelable(false)
                .setNegativeButton("否", ((dialog, which) ->{
                    Toast.makeText(this, "取消保存", Toast.LENGTH_SHORT).show();
                    rb.clearCheck();
                }))
                .setPositiveButton("是", (dialog, which) ->{
                    // 提交表单
                    RequestQueue queue = Volley.newRequestQueue(this);
                    String url = Config.url + "/sjq/flocculationProduceMaintenanceDay/add_recorder";

                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    Log.d("zys", response);
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");
                                        if (code.equals("200")){
                                            normal_rb.setClickable(false);
                                            abnormal_rb.setClickable(false);
                                            Toast.makeText(xuningribaoyang.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        }
                                        else
                                            Toast.makeText(xuningribaoyang.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(xuningribaoyang.this,
                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {
                            Map<String, String> map=new HashMap<>();
                            map.put("equipment_name", equipment_name);
                            map.put("maintenance_content", "-1");
                            map.put("is_normal","正常");
                            map.put("remarks", "");
                            map.put("operator", name);
                            Log.d("fact",factory);
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                })
                .show();
    }

    public void saveAbnormal(String equipment_name, RadioButton normal_rb, RadioButton abnormal_rb,RadioGroup rb) {
        final EditText equipment_problem = new EditText(this);
        equipment_problem.setHint("   输入问题:");
        new AlertDialog.Builder(this)
                .setTitle("请填写 “"+ equipment_name +"” 异常原因？")
                .setView(equipment_problem)
                .setCancelable(false)
                .setNegativeButton("取消", ((dialog, which) ->{
                    Toast.makeText(this, "取消保存", Toast.LENGTH_SHORT).show();
                    rb.clearCheck();
                }
                ))
                .setPositiveButton("提交", (dialog, which) ->{
                    // 提交表单
                    RequestQueue queue = Volley.newRequestQueue(this);
                    String url = Config.url + "/sjq/flocculationProduceMaintenanceDay/add_recorder";

                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    Log.d("jy", response);
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");
                                        if (code.equals("200")){
                                            normal_rb.setClickable(false);
                                            abnormal_rb.setClickable(false);
                                            Toast.makeText(xuningribaoyang.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        }
                                        else
                                            Toast.makeText(xuningribaoyang.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(xuningribaoyang.this,
                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {
                            Map<String, String> map=new HashMap<>();
                            map.put("equipment_name", equipment_name);
                            map.put("maintenance_content", "-1");
                            map.put("is_normal","异常");
                            map.put("remarks", "异常" + equipment_problem.getText().toString());
                            map.put("operator", name);
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                })
                .show();
    }
    public void allDone(String equipment_name){
        new AlertDialog.Builder(this)
                .setTitle(" “"+ equipment_name +"” 未检查，是否退出")
                .setCancelable(false)
                .setNegativeButton("否", ((dialog, which) -> {
                    return;
                }))
                .setPositiveButton("是", (dialog, which) ->{
                    xuningribaoyang.this.finish();
                })
                .show();
    }
}